package state.inmemony;

import org.apache.storm.state.KeyValueState;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.topology.base.BaseStatefulBolt;
import org.apache.storm.tuple.Tuple;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:RenPu
 * @Date: 2020/4/20 14:09
 * @Version: 1.0
 * @description:
 */
public class WordCountBolt extends BaseStatefulBolt<KeyValueState<String,Long>> {

    private KeyValueState<String,Long> state=null;


    /**
     * 执行方法
     * @param tuple
     */
    @Override
    public void execute(Tuple tuple) {

        String word = tuple.getStringByField("word");
        Long num = state.get(word);
        if(num==null){
            state.put(word,1L);
        }else {
            state.put(word,state.get(word));
        }

    }





    @Override
    public void initState(KeyValueState<String, Long> entries) {

    }
}
